// pages/askToBuyIssue/askToBuyIssue.js
import httpsUtils from '../../utils/https.js';
import commonUtils from '../../utils/common.js';
import myUtils from '../../utils/util.js';
import myShowToast from '../../template/toast/showToast';//引入消息提醒暴露的接口  

const app = getApp();
var imgId = "";
var onetClass = [];
var secondsClass = [];
var secondsClassId = [];
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userId:'', //用户id
    /*商圈选择器*/
    areaId: '',
    busCirList: [],
    buyClassList: [],
    colorSelects: '',//颜色选中
    sizeSelects: '',//尺码选中
    /*分类选择器*/
    wantBuyTypeId: '',
    initTypeName:'',
    index: -1,
    multiArray: [[''], ['']],
    multiIndex: [-1, -1],
    /**地址选择器 */
    region: [],
    initAddress:'',//初始化地址
    //textarea.js
    originalPhoneNum: '',
    phoneNum: '',
    phoneHidden: false,//是否隐藏完全手机号
    wxNum: '',//微信号
    contactName:'',//联系人
    focus: false,
    hint: '请输入手机号码',
    nameHint: '请输入联系人姓名(非必填)',
    wxHint: '请输入微信号码(非必填)',
    resHint: '请输入备用电话(非必填)',
    countHint: '请输入商品数量',
    srcImg: [[]],
    srcImgPath: [[]],
    colorSelectList: [],//颜色选择列表   
    mySelectColorName: '',//已选择的颜色名称
    mySelectColorId: [],//已选择的颜色id
    isScreen: false,//显示遮罩
    hidden: false,
    //颜色列表
    isSize: false,
    sizeSelectList: [],//尺码列表
    mySelectSizeName: '',//已选择的尺寸名称
    mySelectSizeId: [],//已选择的尺寸id
    changed: false,
    showModalStatus: false,
    isIndex: false,

    disable: true,
    areaName: '', //商圈名称
    areaIds: '', //商圈id

    specialType: 0, //特殊权限，默认0表示无，1表示求购修改号码

    showFlag: false, //显示分享
    shareImagePath: '', //分享url
    shareId: '', //分享id
    showScrollStatus: false,

    describe: '这个款谁家有，有货的联系我!!!'
  },
  preventD: function () { },
  /**
   * 求货管理
   */
  gotoDel: function () {
    wx.navigateTo({
      url: '../managementPurchasing/managementPurchasing',
    })
  },
  /**
   * 再添加一款图片
   */
  addGoods: function () {
    var that = this;
    if (that.data.srcImg.length < 3) {
      var newSrcImg = [];
      var newSrcImgPath = [];
      that.data.srcImg.push(newSrcImg);
      that.data.srcImgPath.push(newSrcImgPath);
      that.setData({
        srcImg: that.data.srcImg,
        srcImgPath: that.data.srcImgPath
      });
    } else {
      myShowToast.showToast({ title: '每次最多发布3款求货信息' });
    }
  },
  /**
   * 继续发布
   */
  publishAgain: function () {
    var that = this;
    that.setData({
      disable: true,
      showScrollStatus: false,
      showFlag: false
    });
  },
  /**
   * 返回上一页
   */
  gotoLastPage: function () {
    wx.setStorageSync("areaIds", "");
    wx.setStorageSync("areaName", "");
    var that = this;
    if (!that.data.isIndex || that.data.isIndex == 'false') {
      var pages = getCurrentPages();
      if (pages.length >= 2 && pages[pages.length - 2].route == 'pages/askToBuy/askToBuy') {
        app.globalData.isFlush = true;
        wx.navigateBack({
          delta: 1
        })
      } else {
        wx.redirectTo({
          url: '../askToBuy/askToBuy',
          success: function () {
            wx.showToast({
              title: '发布成功',
            })
          },
        })
      }
    } else {
      wx.switchTab({
        url: '../index/index',
      })
    }
  },
  /**
    * 删除图片
    */
  delImg: function (e) {
    var that = this;
    var oneIndex = e.currentTarget.dataset.oneIndex;
    var index = e.currentTarget.dataset.index;
    var srcImg = that.data.srcImg;
    var srcImgPath = that.data.srcImgPath;
    srcImg[oneIndex].splice(index, 1);
    srcImgPath[oneIndex].splice(index, 1);
    that.setData({
      srcImg: srcImg,
      srcImgPath: srcImgPath
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (options.isIndex != undefined) {
      that.setData({
        isIndex: options.isIndex,
      })
    }

    //初始化商圈
    wx.setStorageSync("areaIds", "");
    wx.setStorageSync("areaName", "");


    /**
     * 初始化缓存
     */
    that.initCache();

    /*商圈选择器*/
    httpsUtils.getData({
      _url: app.globalData._url + '/tradeArea/selectList',
      data: '',
    }, function (json) {
      if (json.data && json.success) {
        that.setData({
          busCirList: json.data,
        })
      }
    })
    /*分类选择器*/
    httpsUtils.getData({
      _url: app.globalData._url + '/wantBuyType/selectWantBuyTypeTwoList',
    }, function (json) {
      if (json.data && json.success) {
        var totalArray = [];
        for (let obj of json.data.list) {
          onetClass.push(obj.typeName);
          var secondType = [];
          var secondTypeId = [];
          for (let objTwo of obj.wantBuyTypeList) {
            secondType.push(objTwo.typeName);
            secondTypeId.push(objTwo.id);
          }
          secondsClass.push(secondType);
          secondsClassId.push(secondTypeId);
        };
        totalArray[0] = onetClass;
        totalArray[1] = secondsClass[0]
        that.setData({
          buyClassList: json.data.list,
          multiArray: totalArray
        })
      }
    })
    /*颜色数据*/
    httpsUtils.getData({
      _url: app.globalData._url + '/colour/selectListByUserId',
      data: '',
    }, function (json) {
      if (json.data && json.success) {
        var colorSelectList = [];
        for (let obj of json.data) {
          var isExist = false;
          for (let myObj of that.data.mySelectColorId) {
            if (obj.id == myObj) {
              isExist = true;
              break;
            }
          }
          var colorData = { 'id': obj.id, 'colourName': obj.colourName, 'colourValue': obj.colourValue, 'checked': isExist }
          colorSelectList.push(colorData);
        }
        that.setData({
          colorSelectList: colorSelectList,
        })
      }
      if (json.success == false && json.code == 'OVERTIME') {
        wx.showModal({
          title: '登陆提醒',
          content: '需要您登陆才能继续',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '../wxLogin/wxLogin?type=2&isTab=true',
              })
            } else if (res.cancel) {
              wx.switchTab({
                url: '../index/index',
              })
            }
          }
        })

      }
    })

    /*尺码数据*/
    httpsUtils.getData({
      _url: app.globalData._url + '/size/selectListByUserId',
      data: '',
    }, function (json) {
      if (json.data && json.success) {
        var sizeSelectList = [];
        for (let obj of json.data) {
          var isExist = false;
          for (let myObj of that.data.mySelectSizeId) {
            if (obj.id == myObj) {
              isExist = true;
              break;
            }
          }
          var sizeData = { 'id': obj.id, 'sizeName': obj.sizeName, 'checked': isExist }
          sizeSelectList.push(sizeData);
        }
        that.setData({
          sizeSelectList: sizeSelectList,
        })
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    var that = this;
    var userInfo = wx.getStorageSync("userInfo");
    if (myUtils.isBlank(userInfo)) {
      wx.showModal({
        title: '登陆提醒',
        content: '需要您登陆才能继续',
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '../wxLogin/wxLogin?type=2&isTab=true',
            })
          } else if (res.cancel) {
            wx.switchTab({
              url: '../index/index',
            })
          }
        }
      })
      return;
    }

    that.setData({
      originalPhoneNum: userInfo.phone, 
      phoneNum: userInfo.phone,
      wxNum: userInfo.phone,
      specialType: userInfo.specialType,
      areaName: wx.getStorageSync("areaName"),
      areaIds: wx.getStorageSync("areaIds"),
      userId: userInfo.id
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    var shareImagePath = that.data.shareImagePath;
    if (shareImagePath != '') {
      that.setData({
        showScrollStatus: false
      })
      return {
        title: '这些款谁家有，点开联系我',
        path: 'pages/askToBuyShare/askToBuyShare?id=' + that.data.userId,
        imageUrl: that.data.shareImagePath
      }
    }
  },
  /**
   * 初始化缓存
   */
  initCache:function(){
    var that = this;
    httpsUtils.getData({
      _url: app.globalData._url + '/wantBuy/publishCache',
      data: '',
    }, function (json) {
      if (json.data && json.success) {
        var obj = json.data;
        wx.setStorageSync("areaIds", obj.tradeAreaId);
        wx.setStorageSync("areaName", obj.tradeAreaName);
        that.setData({
          areaName: obj.tradeAreaName,
          areaIds: obj.tradeAreaId,
          wantBuyTypeId: obj.wantBuyTypeId,
          initTypeName: obj.wantBuyTypeName,
          phoneHidden: obj.isHidden == 1 ? true : false,
          phoneNum: obj.isHidden == 1 ? myUtils.hideStr(that.data.originalPhoneNum, 3, 8, '*') : that.data.originalPhoneNum,
          wxNum: obj.wx,
          contactName: obj.contactName,
          countResult: obj.goodsNum,
          initAddress: obj.address,
          mySelectColorName: obj.colourName != null ? obj.colourName.replace(/、/g, ' ') : '',
          mySelectColorId: obj.colourId != null ? obj.colourId.split(",") : [],
          mySelectSizeName: obj.sizeName != null ? obj.sizeName.replace(/、/g, ' ') : '',
          mySelectSizeId: obj.sizeId != null ? obj.sizeId.split(",") : [],
        })
      }
    })
  },
  /**
   * 事件函数
   */
  selectProColor: function (e) {
    this.setData({
      isScreen: true
    })
    this.showModal();
  },
  /**
   * 隐藏弹出层
   */
  hideMyModal: function () {
    if (this.data.showModalStatus) {
      this.resProColor();
      this.setData({ isScreen: false })
    }
    if (this.data.isSize) {
      this.resProSize();
      this.setData({ isSize: false })
    }
  },
  /**
   * 选择颜色结果
   */
  resProColor: function (e) {
    var colorSelectList = this.data.colorSelectList;
    var colorName = '';
    for (let obj of colorSelectList) {
      if (obj.checked) {
        colorName += obj.colourName + " ";
      }
    }
    this.setData({ mySelectColorName: colorName });
    this.hideModal();
    this.setData({ isScreen: false })
  },
  /**
   * 打开选择尺寸样板
   */
  selectProSize: function (e) {
    this.setData({ isSize: true })
    this.showModal();
  },
  /**
   * 选择尺寸结果
   */
  resProSize: function (e) {
    var sizeSelectList = this.data.sizeSelectList;
    var sizeName = '';
    for (let obj of sizeSelectList) {
      if (obj.checked) {
        sizeName += obj.sizeName + " ";
      }
    }
    this.setData({ mySelectSizeName: sizeName });
    this.hideModal();
    this.setData({ isSize: false })
  },

  /**
    * 选择添加样本图方式
    */
  addPhotoType: function (e) {
    var that = this;
    if (that.data.srcImg[e.currentTarget.dataset.oneIndex].length < 3) {
      wx.showActionSheet({
        itemList: ['从相册中选择', '拍照'],
        itemColor: "#4A4A4A",
        success: function (res) {
          if (!res.cancel) {
            if (res.tapIndex == 0) {
              that.addPhoto('album', e.currentTarget.dataset.oneIndex)
            } else if (res.tapIndex == 1) {
              that.addPhoto('camera', e.currentTarget.dataset.oneIndex)
            }
          }
        }
      })
    } else {
      myShowToast.showToast({ title: '每款最多添加3张图片' });
    }
  },

  /*添加样本图*/
  addPhoto: function (type, oneIndex) {
    var that = this;
    wx.chooseImage({
      count: 3, // 默认9
      sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: [type], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths;
        for (let obj of tempFilePaths) {
          if (that.data.srcImg[oneIndex].length < 3) {
            that.data.srcImg[oneIndex].push({ src: obj });
            var _src = that.data.srcImg;
            that.setData({
              srcImg: _src
            });
            that.data.srcImgPath[oneIndex].push(obj);
          }
        }
      }
    })
  },
  /**选择器 */
  bindMultiPickerChange: function (e) {
    this.setData({
      wantBuyTypeId: secondsClassId[e.detail.value[0]][e.detail.value[1]],
      multiIndex: e.detail.value
    })
  },
  bindMultiPickerColumnChange: function (e) {
    var data = {
      multiArray: this.data.multiArray,
      multiIndex: this.data.multiIndex
    };

    //避免直接选择父类为空
    if (data.multiIndex[0] == -1) {
      data.multiIndex[0] = 0;
      this.setData(data);
    }
    //避免直接选择子类为空
    if (data.multiIndex[1] == -1) {
      data.multiIndex[1] = 0;
      this.setData(data);
    }

    data.multiIndex[e.detail.column] = e.detail.value;
    switch (e.detail.column) {
      case 0:
        switch (data.multiIndex[0]) {
          default:
            data.multiArray[1] = secondsClass[data.multiIndex[0]];
            break;
        }
        data.multiIndex[1] = 0;
        break;
      case 1:
        switch (data.multiIndex[0]) {
        }
        break;
    }
    this.setData(data);
  },
  /*商圈选择器*/
  bindbusCirChange: function (e) {
    this.setData({
      areaId: this.data.busCirList[e.detail.value].id,
      index: e.detail.value,
    })
  },
  /*分类选择器*/
  proClass: function (e) {
    this.setData({
      multiIndex: e.detail.value,
    })
  },

  /* 手机号输入框 */
  bindInputBlur: function (e) {
    var phoneNum = e.detail.value;
    if (!myUtils.isMobile(phoneNum)) {
      myShowToast.showToast({ title: '联系电话格式错误' });
    }
    this.setData({
      originalPhoneNum: phoneNum,
      phoneNum: phoneNum
    })
  },
  /**
   * 是否隐藏手机号
   */
  isHiddenPhone: function (e) {
    var that = this;
    if (that.data.phoneHidden) {
      this.setData({
        phoneHidden: false,
        phoneNum: that.data.originalPhoneNum
      })
    } else {
      this.setData({
        phoneHidden: true,
        phoneNum: myUtils.hideStr(that.data.originalPhoneNum, 3, 8, '*')
      })
    }
  },
  /*备用电话*/
  resPhone: function (e) {
    if (e.detail.value != '') {
      var PhoneReg = new RegExp('^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$');
      var phones = PhoneReg.exec(e.detail.value);
      if (phones) {
        this.setData({
          resResult: e.detail.value,
        })
      } else {
        this.setData({
          resResult: '',
          resHint: '输入有误，可重新输入'
        })
      }
    } else {
      this.setData({
        resResult: '',
      })
    }
  },
  /*姓名输入框 */
  phoneCodeCheck: function (e) {
    this.setData({
      cliName: e.detail.value
    })
  },
  /*数量输入框*/
  proCount: function (e) {
    var conutReg = new RegExp('[1-9]');
    var pro_count = conutReg.exec(e.detail.value);
    if (pro_count) {
      if (e.detail.value <= 99999 && e.detail.value > 0) {
        this.setData({
          countResult: e.detail.value,
        })
      } else if (e.detail.value && e.detail.value > 99999) {
        this.setData({
          countResult: 99999,
        })
      }
    } else {
      this.setData({
        countResult: '',
        countHint: '商品数量输入有误'
      })
    }
  },
  /*地址选择器*/
  bindRegionChange: function (e) {
    this.setData({
      region: e.detail.value
    })
  },
  /**商品描述文本框 */
  bindButtonTap: function () {
    this.setData({
      focus: true,
    })
  },
  bindTextAreaBlur: function (e) {
    this.setData({
      focus: false,
      describe: e.detail.value,
    })
  },
  focusInput: function () {
    this.setData({
      focus: true,
    })
  },
  /*选中颜色*/
  checkboxChange: function (e) {
    var colorSelectList = this.data.colorSelectList;
    var checked = e.currentTarget.dataset.checkid;
    for (let obj of colorSelectList) {
      if (obj.id == checked) {
        obj.checked = !obj.checked;
      }
    }
    this.setData({
      colorSelectList: colorSelectList,
    })
  },

  /*颜色请求*/
  colorFormSubmit: function (e) {
    var that = this;
    const colorName = e.detail.value['colorName'];
    if (myUtils.isBlank(colorName)) {
      wx.showToast({
        title: "颜色名不能为空"
      })
      return;
    }
    httpsUtils.postData({
      _url: app.globalData._url + '/colour/addNew',
      data: { colourName: colorName },
    }, function (json) {
      if (json.data && json.success) {
        var colorSelectList = [];
        colorSelectList = that.data.colorSelectList;
        var obj = json.data;
        var colorData = { 'id': obj.id, 'colourName': obj.colourName, 'colourValue': obj.colourValue, 'checked': true }
        colorSelectList.push(colorData);
        that.setData({
          colorSelectList: colorSelectList,
        })
      } else {
        wx.showToast({
          title: json.msg,
          icon: 'none'
        })
      }
    })
  },
  /*选中尺码*/
  checkSizeChange: function (e) {
    var sizeSelectList = this.data.sizeSelectList;
    var checked = e.currentTarget.dataset.sizeid;
    for (let obj of sizeSelectList) {
      if (obj.id == checked) {
        obj.checked = !obj.checked;
      }
    }
    this.setData({
      sizeSelectList: sizeSelectList,
    })
  },
  /*尺码请求*/
  sizeFormSubmit: function (e) {
    var that = this;
    const sizeName = e.detail.value['sizeName'];
    if (myUtils.isBlank(sizeName)) {
      wx.showToast({
        title: "尺码名不能为空"
      })
      return;
    }
    httpsUtils.getData({
      _url: app.globalData._url + '/size/addNew',
      data: { sizeName: sizeName },
    }, function (json) {
      if (json.data && json.success) {
        var sizeSelectList = [];
        sizeSelectList = that.data.sizeSelectList;
        var obj = json.data;
        var sizeData = { 'id': obj.id, 'sizeName': obj.sizeName, 'checked': true }
        sizeSelectList.push(sizeData);
        that.setData({
          sizeSelectList: sizeSelectList,
        })
      } else {
        wx.showToast({
          title: json.msg,
          icon: 'none'
        })
      }
    })
  },
  /**
   * 提交发布数据
   */
  formSubmit: function (e) {
    var that = this;
    if (!that.data.disable) {
      return;
    }

    var imageUrl = '';
    var coverUrl = '';

    var uploadImagePath = [];
    for (let obj of that.data.srcImgPath){
      if(obj.length > 0){
        uploadImagePath.push(obj);
      }
    }
    if (uploadImagePath.length <= 0) {
      myShowToast.showToast({ title: '请添加求货图片' });
      return;
    }

    //商圈地址
    var areaId = wx.getStorageSync("areaIds");
    if (myUtils.isBlank(areaId)) {
      myShowToast.showToast({ title: '请选择发布商圈' });
      return;
    }

    //商品分类
    var wantBuyTypeId = that.data.wantBuyTypeId;
    if (myUtils.isBlank(wantBuyTypeId)) {
      myShowToast.showToast({ title: '请选择商品分类' });
      return;
    }
    //电话
    var phone = that.data.originalPhoneNum;
    if (!myUtils.isMobile(phone)) {
      myShowToast.showToast({ title: '联系电话格式错误' });
      return;
    }
    var phoneHidden = that.data.phoneHidden ? 1 : 0;

    //微信
    var wxNum = e.detail.value['wxNum'];

    // //联系人
    // var cliName = e.detail.value['cliName'];

    // //数量
    // var proCount = e.detail.value['proCount'];
    // if (myUtils.isBlank(proCount)) {
    //   myShowToast.showToast({ title: '请填写需要数量' });
    //   return;
    // }

    //地址
    var address = e.detail.value['address'];
    if (myUtils.isBlank(address)) {
      myShowToast.showToast({ title: '请选择需求地址' });
      return;
    }

    //描述
    var describe = that.data.describe;

    //颜色
    var colorArray = [];
    for (let obj of that.data.colorSelectList) {
      if (obj.checked) {
        colorArray.push(obj.id);
      }
    }
    var colorIds = myUtils.concatStr(colorArray, ",");

    //尺寸
    var sizeArray = [];
    for (let obj of that.data.sizeSelectList) {
      if (obj.checked) {
        sizeArray.push(obj.id);
      }
    }
    var sizeIds = myUtils.concatStr(sizeArray, ",");
    that.setData({
      disable: false,
    });

    wx.showLoading({
      title: '求货提交中',
      mask: true
    });
    setTimeout(function () {
      wx.hideLoading()
    }, 15000)

    
    commonUtils.myUploadFileBatch(uploadImagePath, true, function (res) {
      if (res.length <= 0) {
        wx.hideLoading();
        that.setData({
          disable: true,
        });
        wx.showModal({
          title: '提示',
          content: '图片上传失败，请重新发布',
          showCancel: false
        })
        return;
      } else {
        that.setData({
          shareImagePath: uploadImagePath[0][0]
        });
      }

      var goodsImgUrls = [];
      var imageUrl = '';
      for (let obj of res) {
        goodsImgUrls.push(myUtils.concatStr(obj, "***"));
      }
      imageUrl = myUtils.concatStr(goodsImgUrls, ",")

      var submitData = {
        "imageUrls": imageUrl,
        "tradeAreaId": areaId,
        "wantBuyTypeId": wantBuyTypeId,
        "phone": phone,
        "wx": wxNum,
        "address": address,
        "goodsDescribe": describe,
        "colourId": colorIds,
        "sizeId": sizeIds,
        "isHidden": phoneHidden
      }
      that.submitWant(submitData);
    });


  },
  /**
   * 提交数据
   */
  submitWant: function (data) {
    var that = this;
    httpsUtils.postData({
      _url: app.globalData._url + '/wantBuy/addBatch/' + that.data.userId,
      data: JSON.stringify(data),
    }, function (json) {
      wx.hideLoading();
      if (json.data && json.success) {
        wx.showToast({
          title: '发布成功',
          success: function () {
            that.setData({
              showFlag: true,
              srcImgPath: [[]],
              srcImg: [[]],
              showScrollStatus: true
            });
          }
        })
      } else if (json.data.msg == "1") {
        that.setData({
          disable: true,
        });
        wx.showModal({
          title: '提示',
          content: json.data.tip,
          success: function (res) {
            if (res.confirm) {
              data.isMember = 1
              that.submitWant(data);
              //console.log('用户点击确定')
            } else if (res.cancel) {
              wx.hideLoading()
              //console.log('用户点击取消')
            }
          }
        })
      } else if (json.data.msg == "2") {
        that.setData({
          disable: true,
        });
        wx.showModal({
          title: '提示',
          content: json.data.tip,
          success: function (res) {
            if (res.confirm) {
              data.isMember = 2
              that.submitWant(data);
              //console.log('用户点击确定')
            } else if (res.cancel) {
              wx.hideLoading()
              //console.log('用户点击取消')
            }
          }
        })
      } else if (json.data.msg == "3") {
        that.setData({
          disable: true,
        });
        wx.showModal({
          title: '提示',
          content: json.data.tip,
          success: function (res) {
            if (res.confirm) {
              data.isMember = 2
              that.submitWant(data);
              //console.log('用户点击确定')
            } else if (res.cancel) {
              wx.hideLoading()
              //console.log('用户点击取消')
            }
          }
        })
      } else if (json.data.msg == "4") {
        that.setData({
          disable: true,
        });
        wx.showModal({
          title: '提示',
          content: json.data.tip,
          success: function (res) {
            if (res.confirm) {
              wx.hideLoading()
              wx.navigateTo({
                url: '../payAdd/payAdd?isTab=1&money=' + json.data.money,
              })
            } else if (res.cancel) {
              wx.hideLoading()
              //console.log('用户点击取消')
            }
          }
        })
      }
    })
  },
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    this.setData({
      animationData: animation.export(),
      showModalStatus: true,
    })
  },
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    this.setData({
      animationData: animation.export(),
      showModalStatus: false,
    })
  }

})